// ====================
// 核心JS代码 - 复制到项目
// ====================

// 确保消息容器存在
if (!document.getElementById('messageContainer')) {
	const container = document.createElement('div');
	container.className = 'message-container';
	container.id = 'messageContainer';
	document.body.appendChild(container);
}

// 消息弹框函数
function showMessage(type, content, title = '', duration = 3000) {
	const messageContainer = document.getElementById('messageContainer');
	const messageId = 'msg-' + Date.now();

	const messageBox = document.createElement('div');
	messageBox.className = `message-box ${type}`;
	messageBox.id = messageId;

	// 图标映射
	const icons = {
		success: '✓',
		error: '✕',
		warning: '!',
		info: 'i'
	};

	// 默认标题
	const defaultTitles = {
		success: '成功',
		error: '错误',
		warning: '警告',
		info: '信息'
	};

	messageBox.innerHTML = `<div class="message-icon">${icons[type]}</div><div class="message-content"><div class="message-title">${title || defaultTitles[type]}</div><div class="message-text">${content}</div></div><button class="close-btn" onclick="closeMessage('${messageId}')">×</button>`;

	messageContainer.appendChild(messageBox);

	// 触发动画
	setTimeout(() => {
		messageBox.classList.add('show');
	}, 10);

	// 自动关闭
	if (duration > 0) {
		setTimeout(() => {
			closeMessage(messageId);
		}, duration);
	}
}

// 关闭消息
function closeMessage(id) {
	const message = document.getElementById(id);
	if (message) {
		message.classList.remove('show');
		setTimeout(() => {
			message.remove();
		}, 400);
	}
}